package com.yangyu.controller;

import com.yangyu.currency.StatusCode;
import com.yangyu.message.BaseRsp;
import com.yangyu.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author
 * @version V1.0
 * @Package com.yangyu.controller
 * @date 2021/1/16 22:55
 */
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    @PostMapping("/uploadImg")
    public BaseRsp uploadImg(MultipartFile image) {
        try {
            return uploadService.uploadImg(image);
        } catch (IOException e) {
            e.printStackTrace();
            return new BaseRsp(StatusCode.UploadErrorCode.UPLOAD_IMG_ERROR, "图片上传失败");
        }
    }
}
